<template>
  <div id="gloablheader">
    <a-row :wrap="false">
      <a-col flex="200px">
        <router-link to="/">
          <div class="title-bar">
            <img src="../assets/monkey.png" alt="logo" class="logo">
            <div class="title">monkey网站</div>
          </div>
        </router-link>
      </a-col>
      <a-col flex="auto">
        <a-menu v-model:selectedKeys="current" mode="horizontal" :items="items" @click="doMenuClick"/>
      </a-col>
      <a-col flex="100px">
        <div class="right-user-bar">
          <a-button class="login-button" type="primary">登录</a-button>
        </div>
      </a-col>
    </a-row>
  </div>
</template>


<script lang="ts" setup>
import { h, ref } from 'vue'
import { HomeOutlined } from '@ant-design/icons-vue'
import { MenuProps } from 'ant-design-vue'
import { useRouter } from 'vue-router'

const items = ref<MenuProps['items']>([
  {
    key: '/',
    icon: () => h(HomeOutlined),
    label: '主页',
    title: '主页',
  },
  {
    key: '/about',
    label: '关于',
    title: '关于',
  },
  {
    key: 'others',
    label: h('a', { href: 'https://www.codefather.cn', target: '_blank' }, '编程导航'),
    title: '编程导航',
  },
])
const router = useRouter();
//高亮显示选择的菜单
const current = ref<string[]>(['/'])
const doMenuClick= ({key} :{key:string})=>{
  router.push(key)
}
/**
 * 路由跳转之后执行
 * @param to router后页面
 * @param from router前页面
 * @param next
 */
router.afterEach((to, from, next)=>{
  current.value = [to. path]
})



</script>

<style scoped>
.title-bar {
  display: flex;
  align-items: center;
}

.title {
  color: black;
  font-size: 18px;
  margin-left: 16px;
}

.logo {
  height: 48px;
}
</style>




